import { createWebHistory, createRouter } from "vue-router";

import HomeView from "../views/HomeView.vue";
import LoginView from "../views/LoginView.vue";

import httpEventEmitter from '../lib/http';

const routes = [
    {
        path: '/',
        component: HomeView
    },
    {
        path: '/login',
        component: LoginView
    }
]

const router = createRouter({
    history: createWebHistory(),
    routes
})

// 登录参数校验错误，跳转到登录界面重新登录
httpEventEmitter.listen('PARAM_CHECK_FAILED', () => {
    router.push('/login');
})

// token失效跳转到登录界面进行重新登陆
httpEventEmitter.listen('INVALID_TOKEN', () => {
    router.push('/login');
})

// 登录成功跳转到首页
httpEventEmitter.listen("LOGIN_SUCCESS", () => {
    router.push('/');
})



export default router;